var correct = 0;

function validatePass(){
	if (document.getElementById("oldpass").value.toString().length == 0) {
		document.getElementById("messageOldPass").innerHTML = 'Грешна парола.';
	} else {
		agent.call('','checkUserPass', 'setMessageOldPass',document.getElementById("oldpass").value.toString());
	}
	
}

function setMessageOldPass(answer){
	if (answer == 1){
		document.getElementById("messageOldPass").innerHTML = 'Паролата е вярна.';
		correct = 1;
	} else {
		document.getElementById("messageOldPass").innerHTML = 'Грешна парола.';
		correct = 0;
	}
}

function matchPass() {
	if (document.getElementById("newpass").value.toString().length < 6) {
		document.getElementById("messageNewPass").innerHTML = 'Късо.';
		return 0;
	} else {
		document.getElementById("messageNewPass").innerHTML = 'Става.';
	}
	
	if (document.getElementById("newpass").value == document.getElementById("rnewpass").value){
		document.getElementById("messageRNewPass").innerHTML = 'OK';
		return 1;
	} else {
		document.getElementById("messageRNewPass").innerHTML = 'Паролите не съвпадат';
	}
	return 0;
}

function submitPasswordChange() {
	if (correct == 1 && matchPass() ==1){
		agent.call('','changePass', 'logout',document.getElementById("oldpass").value.toString(), document.getElementById("newpass").value.toString());
	} else {
		alert('условията не са удовлетворени');
	}
}

function submitSaveToodledo(){
	agent.call('', 'changeToodledoId', 'refresh', document.getElementById("toodledo_id").value.toString(), document.getElementById("tpass").value.toString());
}

function logout(){
	alert('готово. трябва да се логнете с новата парола.');
	window.location = "./logout.php";
}

function refresh(){
	window.top.location.reload(1);
}

